package Third;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

public class ReenterLockCondition implements Runnable {
	public static ReentrantLock lock = new ReentrantLock();
	public static Condition condition = lock.newCondition();
	
	@Override
	public void run() {
		try {
			System.out.println("1");
			lock.lock();
			condition.await();
			System.out.println("Thread is going on.");
		} catch (InterruptedException ex) {
			ex.printStackTrace();
		} finally {
			System.out.print("3");
			lock.unlock();
		}
	}
	
	public static void main(String[] args) throws InterruptedException {
		ReenterLockCondition tl = new ReenterLockCondition();
		Thread t1 = new Thread(tl);
		
		t1.start();
		Thread.sleep(2000);
		
		System.out.println("2");
		lock.lock();
		condition.signal();
		lock.unlock();
	}
}
